package net.xiaoyu233.mitemod.miteite.block;

import net.minecraft.*;
import net.xiaoyu233.mitemod.miteite.item.Items;
import net.xiaoyu233.mitemod.miteite.render.block.SideIconHolder;
import net.xiaoyu233.mitemod.miteite.tileentity.TileEntityRecyclingTable;

import java.util.HashMap;
import java.util.Map;

public class BlockRecyclingTable extends Block implements IContainer {
    private int tableLevel; // 回收台等级
    SideIconHolder sideIconHolder = new SideIconHolder();

    protected BlockRecyclingTable(int par1, Material par2Material, BlockConstants constants, int level) {
        super(par1, par2Material, constants);
        this.setHardness(BlockHardness.furnace);
        this.setStepSound(soundWoodFootstep);
        this.setCreativeTab(CreativeModeTab.tabDecorations);
        this.setMaxStackSize(1);
        this.setLightOpacity(0);
        this.tableLevel = level;
    }

    @Override
    public TileEntity createNewTileEntity(World world) {
        TileEntityRecyclingTable tileEntity = new TileEntityRecyclingTable();
        tileEntity.setTableLevel(tableLevel);
        return tileEntity;
    }

    @Override
    public boolean canBeReplacedBy(int metadata, Block other_block, int other_block_metadata) {
        return false;
    }

    @Override
    public boolean isPortable(World world, EntityLiving entity_living_base, int x, int y, int z) {
        return true;
    }

    public float getCraftingDifficultyAsComponent(int metadata) {
        return -1.0F;
    }

    @Override
    public void breakBlock(World world, int x, int y, int z, int block_id, int metadata) {
        super.breakBlock(world, x, y, z, block_id, metadata);
        world.removeBlockTileEntity(x, y, z);
    }

    public void a(mt mt) {
        String laogblock = "recyclingtable/" + this.tableLevel;
        sideIconHolder.setTexture_top(mt.a(laogblock + "_top"));
        sideIconHolder.setTexture_bottom(mt.a(laogblock + "_bottom"));
        sideIconHolder.setTexture_side(mt.a(laogblock + "_side"));
    }

    public IIcon a(int side, int meta) {
        SideIconHolder icon = sideIconHolder;
        switch (side) {
            //top
            case 1:
                return icon.getTexture_top();
            //bottom
            case 0:
                return icon.getTexture_bottom();
            case 2:
            case 3:
            case 5:
            case 4:
                return icon.getTexture_side();
        }
        return super.a(side, meta);
    }

    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, EnumFace face, float offset_x, float offset_y, float offset_z) {
        if (player.onServer()) {
            TileEntityRecyclingTable tile_entity = (TileEntityRecyclingTable) world.getBlockTileEntity(x, y, z);
            if (tile_entity != null && !tile_entity.isUsing) {
                tile_entity.isUsing = true;
                player.displayGUIRecyclingTable(tile_entity);
            }
        }
        return true;
    }

//    // 检查下方是否有岩浆
//    public static boolean hasLavaBelow(World world, int x, int y, int z) {
//        Block blockAbove = world.getBlock(x, y - 1, z);
//        if (blockAbove != null && blockAbove.blockID == Blocks.lavaStill.blockID )  {
//            return true;
//        }
//        return false;
//    }

    // 获取回收台等级
    public int getTableLevel() {
        return tableLevel;
    }
}